
// import Cookies from 'js-cookie'

const TokenKey = 'YunQue-Token'
const UserKey='YunQue-User'

export function getToken() {
  return localStorage.getItem(TokenKey)
}

export function isTokenExpired(token){
  if (!token) return true; 
  const payload = token.split('.')[1];
  if (!payload) return true;
  const decodedPayload = JSON.parse(atob(payload));
  const exp = decodedPayload.exp;
  const currentTime = Math.floor(Date.now() / 1000);
  return currentTime > exp;
}

export function setToken(token) {
  return localStorage.setItem(TokenKey, token)
}

export function removeToken() {
  return localStorage.removeItem(TokenKey)
}

export function getUser() {
  var userStr=localStorage.getItem(UserKey)
  return JSON.parse(userStr)
}

export function setUser(user) {
  return localStorage.setItem(UserKey,  JSON.stringify(user))
}

export function removeUser() {
  return localStorage.removeItem(UserKey)
}
